import lejos.nxt.*;
import lejos.nxt.addon.*;
import lejos.util.*;	

public class TacToD {

	/**
	 * @param args
	 * @throws InterruptedException 
	 */
	public static void main(String[] args) throws InterruptedException {
		Datalogger dl = new Datalogger();
		MotorPort.A.setPWMMode(BasicMotorPort.BACKWARD);
		MotorPort.B.setPWMMode(BasicMotorPort.BACKWARD);
		MotorPort.A.resetTachoCount();
		
		OpticalDistanceSensor ir = new OpticalDistanceSensor(SensorPort.S1); 
		
		MotorPort.A.controlMotor(20,BasicMotorPort.BACKWARD);
		MotorPort.B.controlMotor(20, BasicMotorPort.BACKWARD);
		

		int tachCount = 0;
		int irDistance;
		
		while(tachCount<4800){
			tachCount = -MotorPort.A.getTachoCount();
			irDistance = ir.getDistance();
			System.out.println(tachCount);
			dl.writeLog(irDistance,tachCount);
			Thread.sleep(20);
		}
		MotorPort.A.controlMotor(0,BasicMotorPort.BACKWARD);
		MotorPort.B.controlMotor(0, BasicMotorPort.BACKWARD);
		dl.transmit();
	}

}
